package com.dao;

import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.NoResultException;
import javax.persistence.NonUniqueResultException;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

import com.entidades.Recado;

@Stateless
public class RecadoDAO extends GenericDAO<Recado> {

	@PersistenceContext(unitName = "Projeto2POD")
	private EntityManager em;
	
	public RecadoDAO(){
		super(Recado.class);
	}
	
//	public RecadoDAO(Class<Recado> entityClass) {
//		super(entityClass);
//		// TODO Auto-generated constructor stub
//	}
	
	public Recado findbyNome(String nome) {
		try{ 
			Query q = em.createQuery("select a from Recado a where a.nome LIKE '%" + nome + "%'");
			return (Recado)q.getSingleResult();
		} catch (NoResultException e) {
			return null;
		} catch (NonUniqueResultException e) {
			return null;
		}catch (NullPointerException e) {
			return null;
		}
	}
	
	public Recado findbyId(int id) {
		try{ 
			Query q = em.createQuery("select rec from Recado rec where rec.id='"+id+"'");
			return (Recado)q.getSingleResult();
		} catch (NoResultException e) {
			return null;
		} catch (NonUniqueResultException e) {
			return null;
		}catch (NullPointerException e) {
			return null;
		}
	}
}
